package Unitest;

/**
 * DsaKeyGenerator.java
 * Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
 */
import java.io.*;
import java.math.*;
import java.security.*;
import java.security.interfaces.*;
class DsaKeyGenerator {
   public static void main(String[] a) {
      int keySize = 1024;
      String output = "test";
      String algorithm = "DSA";
      try {
         genKeyPair(keySize,output,algorithm);
      } catch (Exception e) {
         System.out.println("Exception: "+e);
         return;
      }
   }
   private static void genKeyPair(int keySize, String output, 
         String algorithm) throws Exception {
      KeyPairGenerator kg = KeyPairGenerator.getInstance(algorithm);
      kg.initialize(keySize);
      System.out.println();
      System.out.println("KeyPairGenerator Object Info: ");
      System.out.println("Algorithm = "+kg.getAlgorithm());
      System.out.println("Provider = "+kg.getProvider());
      System.out.println("Key Size = "+keySize);
      System.out.println("toString = "+kg.toString());
      KeyPair pair = kg.generateKeyPair();
      
      DSAPrivateKey priKey = (DSAPrivateKey) pair.getPrivate();
      DSAPublicKey pubKey = (DSAPublicKey) pair.getPublic();
      DSAParams params = pubKey.getParams();
      System.out.println(params.getG().toString(16));
   }
}